package wsz.sqlSession;

import org.dom4j.DocumentException;
import wsz.config.XmlConfigBuilder;
import wsz.pojo.Configuration;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author wsz
 * @date 2021/10/1 0:53
 **/
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream is) throws PropertyVetoException, DocumentException {
        // 读取/解析/生成Configuration
        XmlConfigBuilder builder = new XmlConfigBuilder();
        Configuration configuration = builder.parseConfig(is);

        // 工厂模式：创建sqlSessionFactory
        DefaultSqlSessionFactory sessionFactory = new DefaultSqlSessionFactory(configuration);

        return sessionFactory;
    }
}
